﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Meqs.Entity;
using Meqs.Logic.Interface;

namespace Meqs.Logic.Implement
{
    public class ClassEvalDetailLogic : CommonLogic<ClassEvalDetail, int>, IClassEvalDetailLogic
    {
        private ISchoolInfoLogic _schoolLogic;
        public ClassEvalDetailLogic(ISchoolInfoLogic schoolLogic)
        {
            _schoolLogic = schoolLogic;
        }

        #region Implementation of ICommonLogic<ClassEvalDetail, int>

        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Create(ClassEvalDetail entity)
        {
            return CreateObject(entity);
        }

        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(ClassEvalDetail entity)
        {
            return UpdateObject(entity);
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public int Delete(int entityId)
        {
            return DeleteObject(entityId);
        }

        /// <summary>
        /// 删除所有对象
        /// </summary>
        /// <returns></returns>
        public int DeleteAll()
        {
            return DeleteAllObject();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public ClassEvalDetail FindById(int entityId)
        {
            return FindObjectById(entityId);
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount()
        {
            return FindObjectByCount();
        }

        /// <summary>
        /// 检索对象
        /// </summary>
        public IList<ClassEvalDetail> FindAll()
        {
            return FindAllObject();
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount(Hashtable table)
        {
            return FindObjectByCount(table);
        }

        /// <summary>
        /// 检索对象
        /// </summary>
        public IList<ClassEvalDetail> FindAll(Hashtable table)
        {
            return FindObject(table);
        }

        #endregion

        /// <summary>
        /// 获取班级下所有学生在指定的日期内的所有德育评价之明细
        /// </summary>
        /// <param name="classID">班级ID</param>
        /// <param name="reportType">
        /// 报表类型
        /// 1:日报
        /// 2:周报
        /// 3:月报
        /// </param>
        /// <param name="schoolYear">学年，不填为当前学年</param>
        /// <param name="term">学期，不填为当前学期</param>
        /// <param name="schoolMark">学校编号</param>
        /// <returns></returns>
        public IList<ScoreInputClassEntity> GetScoreInputEntityByClass(int classID, int reportType, DateTime evalDate, int? schoolYear, int? term, string schoolMark)
        {
            if (schoolYear == null || term == null)
            {
                SchoolInfo school = _schoolLogic.FindBySchoolMark(schoolMark);
                schoolYear = school.SchoolYear;
                term = school.SchoolTerm;
            }
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", schoolMark);
            ht.Add("ClassID", classID);
            ht.Add("ReportDate", evalDate);
            ht.Add("ReportType", reportType);
            ht.Add("SchoolYear", schoolYear);
            ht.Add("Term", term);
            return FindCustomer<ScoreInputClassEntity>("ClassEvalDetail.GetScoreInputEntityByClass", ht);
        }

        /// <summary>
        /// 保存
        /// </summary>
        public int InsertClassEvalDetail(ClassEvalDetail classEvalDetail, string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("ClassEvalDetail", classEvalDetail);
            ht.Add("SchoolMark", schoolMark);
            return (int)InsertCustomer("ClassEvalDetail.InsertClassEvalDetail", ht);
        }
    }
}
